home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2009 February / PCWFEB09.iso / Software / Resources / Chat & Communication / Digsby build 37 / digsby_setup.exe / lib / chunk.pyo (.txt) < prev    next >
Python Compiled Bytecode  |  2008-10-13  |  3KB  |  138 lines

  1. # Source Generated with Decompyle++
  2. # File: in.pyo (Python 2.5)
  3.  
  4.  
  5. class Chunk:
  6.     
  7.     def __init__(self, file, align = True, bigendian = True, inclheader = False):
  8.         import struct as struct
  9.         self.closed = False
  10.         self.align = align
  11.         if bigendian:
  12.             strflag = '>'
  13.         else:
  14.             strflag = '<'
  15.         self.file = file
  16.         self.chunkname = file.read(4)
  17.         if len(self.chunkname) < 4:
  18.             raise EOFError
  19.         
  20.         
  21.         try:
  22.             self.chunksize = struct.unpack(strflag + 'L', file.read(4))[0]
  23.         except struct.error:
  24.             raise EOFError
  25.  
  26.         if inclheader:
  27.             self.chunksize = self.chunksize - 8
  28.         
  29.         self.size_read = 0
  30.         
  31.         try:
  32.             self.offset = self.file.tell()
  33.         except (AttributeError, IOError):
  34.             self.seekable = False
  35.  
  36.         self.seekable = True
  37.  
  38.     
  39.     def getname(self):
  40.         return self.chunkname
  41.  
  42.     
  43.     def getsize(self):
  44.         return self.chunksize
  45.  
  46.     
  47.     def close(self):
  48.         if not self.closed:
  49.             self.skip()
  50.             self.closed = True
  51.         
  52.  
  53.     
  54.     def isatty(self):
  55.         if self.closed:
  56.             raise ValueError, 'I/O operation on closed file'
  57.         
  58.         return False
  59.  
  60.     
  61.     def seek(self, pos, whence = 0):
  62.         if self.closed:
  63.             raise ValueError, 'I/O operation on closed file'
  64.         
  65.         if not self.seekable:
  66.             raise IOError, 'cannot seek'
  67.         
  68.         if whence == 1:
  69.             pos = pos + self.size_read
  70.         elif whence == 2:
  71.             pos = pos + self.chunksize
  72.         
  73.         if pos < 0 or pos > self.chunksize:
  74.             raise RuntimeError
  75.         
  76.         self.file.seek(self.offset + pos, 0)
  77.         self.size_read = pos
  78.  
  79.     
  80.     def tell(self):
  81.         if self.closed:
  82.             raise ValueError, 'I/O operation on closed file'
  83.         
  84.         return self.size_read
  85.  
  86.     
  87.     def read(self, size = -1):
  88.         if self.closed:
  89.             raise ValueError, 'I/O operation on closed file'
  90.         
  91.         if self.size_read >= self.chunksize:
  92.             return ''
  93.         
  94.         if size < 0:
  95.             size = self.chunksize - self.size_read
  96.         
  97.         if size > self.chunksize - self.size_read:
  98.             size = self.chunksize - self.size_read
  99.         
  100.         data = self.file.read(size)
  101.         self.size_read = self.size_read + len(data)
  102.         if self.size_read == self.chunksize and self.align and self.chunksize & 1:
  103.             dummy = self.file.read(1)
  104.             self.size_read = self.size_read + len(dummy)
  105.         
  106.         return data
  107.  
  108.     
  109.     def skip(self):
  110.         if self.closed:
  111.             raise ValueError, 'I/O operation on closed file'
  112.         
  113.         if self.seekable:
  114.             
  115.             try:
  116.                 n = self.chunksize - self.size_read
  117.                 if self.align and self.chunksize & 1:
  118.                     n = n + 1
  119.                 
  120.                 self.file.seek(n, 1)
  121.                 self.size_read = self.size_read + n
  122.                 return None
  123.             except IOError:
  124.                 pass
  125.             except:
  126.                 None<EXCEPTION MATCH>IOError
  127.             
  128.  
  129.         None<EXCEPTION MATCH>IOError
  130.         while self.size_read < self.chunksize:
  131.             n = min(8192, self.chunksize - self.size_read)
  132.             dummy = self.read(n)
  133.             if not dummy:
  134.                 raise EOFError
  135.                 continue
  136.  
  137.  
  138.